<h1>Listing stocks</h1>

<table>
  <tr>
    <th>Name</th>
    <th>Market value</th>
    <th>Trend</th>
    <th>Action</th>
  </tr>

<% for stock in @stocks %>
  <tr>
    <td><%= link_to stock.name, 
    		:action => 'show',
    		:id		=> stock  %></td>
    <td><%=h stock.market_value %></td>
    <% trend = stock.market_value - stock.days_opening %>
    <td><% if trend == 0 %>
    <img src="/images/side.png" height=10px width=10px />
    <% elsif trend < 0 %>
    <img src="/images/down.png" height=10px width=10px />
    <%= number_with_precision(-trend,2) %>(<%= number_with_precision(-trend/stock.days_opening*100,2) %>%)
    <% else %>
    <img src="/images/up.png" height=10px width=10px />
    <%= number_with_precision(trend, 2) %>(<%= number_with_precision(trend/stock.days_opening*100,2) %>%)
    <% end %>
    </td>
    
    <td><%= link_to 'Buy', 
            :action => 'buy',
            :id      => stock %> |  
		<%= link_to 'Sell', 
            :action => 'sell',
            :id      => stock %></td>
  </tr>
<% end %>
</table>


